package cn.hy.mygame.entity;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;
import cn.hy.mygame.global.Config;
import cn.hy.mygame.model.BaseModel;
import cn.hy.mygame.model.Plant;
import cn.hy.mygame.view.GameView;

public class Flower extends BaseModel implements Plant {
	private int locationX;
	private int locationY;
	private boolean isAlive;
	private int currentIndexFrame = 0;
	private int mapIndex;
	private long lastGiveBithTime = 0;
	
	public Flower (int locationX, int locationY, int mapIndex) {
		this.locationX = locationX;
		this.locationY = locationY;
		this.mapIndex = mapIndex;
		lastGiveBithTime = System.currentTimeMillis();
		isAlive = true;
	}
	
	@Override
	public void drawSelf(Canvas canvas, Paint paint) {
		// TODO Auto-generated method stub
		if (isAlive) {
			canvas.drawBitmap(Config.flowerFrames[currentIndexFrame], locationX, locationY, paint);
			currentIndexFrame = ((++currentIndexFrame) % 8);
			if (System.currentTimeMillis() - lastGiveBithTime > 10000) {
				lastGiveBithTime = System.currentTimeMillis();
				givebirth2Sun();
			}
		}
	}

	public void givebirth2Sun () {
		GameView.getInstance().givebirth2Sun(locationX, locationY);
	}
	
	public int getLocationX() {
		return locationX;
	}

	public void setLocationX(int locationX) {
		this.locationX = locationX;
	}

	public int getLocationY() {
		return locationY;
	}

	public void setLocationY(int locationY) {
		this.locationY = locationY;
	}

	public boolean isAlive() {
		return isAlive;
	}

	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	@Override
	public int getMapIndex() {
		// TODO Auto-generated method stub
		return mapIndex;
	}
	
	@Override
	public int getModelWidth() {
		// TODO Auto-generated method stub
		return Config.flowerFrames[0].getWidth();
	}
}
